{include file="public/_head" /}
<!-- /Navbar -->
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file="public/_left" /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>&nbsp;前台首页
                    </li>
                    <li>食材功效添加</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget radius-bordered">
                            <div class="widget-header bordered-bottom bordered-themeprimary">
                                <span class="widget-caption">食材功效添加</span>
                            </div>
                            <div class="widget-body">
                                <form action="{:url('admin/consecond/add')}" class="form-horizontal">
                                    <div class="form-group">
                                        <label for="test1" class="col-sm-2 control-label no-padding-right"></label>
                                        <div class="col-sm-6">
                                            <button type="button" class="layui-btn" id="test1">上传图片</button>
                                            <div class="layui-upload-list">
                                                <img class="img-responsive" id="demo1">
                                                <p id="demoText"></p>
                                                <p class="help-block">注：请统一上传像素长约210px ，宽约290px ，且小于200k的图片</p>
                                            </div>
                                            <input type="hidden" name="images" id="images">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="title" class="control-label col-sm-2 no-padding-right">食材功效标题</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="title" name="title" placeholder="内容标题" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="content" class="control-label col-sm-2">内容</label>
                                        <div class="col-sm-6">
                                            <textarea name="content" id="content" cols="30" rows="10" class=""></textarea>
                                        </div>
                                        <p></p>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-6">
                                            <button type="submit" id="consecondAdd" class="btn btn-primary">添加</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file="public/_js" /}
<!--富文本编辑器-->
<script src="/Tp5/public/static/lib/ueditor/ueditor.config.js"></script>
<script src="/Tp5/public/static/lib/ueditor/ueditor.all.js"></script>
<script>
    $(function () {
        UE.getEditor('content');

        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: "{:url('admin/carousel/upload')}"
                ,size:200
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //上传成功
                    if (res.code == 1) {
                        $('#images').val(res.url);
                        return layer.msg(res.msg);
                    } else {
                        //如果上传失败
                        return layer.msg(res.msg);
                    }

                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });

        //表单提交
        $('form').submit(function () {
            var res = $(this).serialize();
            var url = $(this).attr('action');
            $.ajax({
                url: url,
                data: res,
                type: 'post',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 1200
                        }, function () {
                            window.location.href = "{:url('admin/consecond/all')}";
                        });
                    } else {
                        layer.alert(data.msg, {
                            icon: 5,
                            anim: 6
                        }, function (index) {
                            layer.close(index);
                        });
                    }
                }
            });
            return false;
        });
    });
</script>